import http from '@/http/http'
import { loadEnv } from 'vite'
import {
    AddUserModel,
    ChangeAvatar,
    ChangePassword,
    InstallParam,
    LoginParam,
    LoginResult,
    SelectRoleParam,
    UserInfo,
    UserListParam
} from './UserModel'
enum Api {
    getImg = '/api/v1/auth/captcha',
    login = '/api/v1/auth/login',
    getUserList = '/api/v1/user/getList',
    getInfo = '/api/v1/user/info',
    getLeftTree = '/api/department/list',
    addAndEditAndDel = '/api/v1/user/user',
    getRoleId = '/api/v1/user/getRoleIdByUserId',
    assignSave = '/api/v1/user/assignRole',
    loginOut = '/api/v1/user/loginOut',
    changePassword = '/api/v1/user/changePassword',
    changeAvatar = '/api/v1/user/changeAvatar',
    installConfig = '/api/v1/auth/installConfig',
    installSave = '/api/v1/auth/install'
}

// 获取验证码
export async function getImageApi() {
    return await http.get(Api.getImg)
}
// 登录
export async function loginApi(params: LoginParam) {
    return await http.post<LoginResult>(Api.login, params)
}
// 获得后台配置信息
export async function getInstallConfigApi() {
    return await http.get(Api.installConfig)
}
// 后台配置提交
export async function installSaveApi(param: InstallParam) {
    return await http.post(Api.installSave, param)
}

// 获取用户信息
export const getInfoApi = async () => {
    return await http.get<UserInfo>(Api.getInfo)
}
// 用户管理左侧部门树
export const getLeftTreeApi = async () => {
    return await http.get(Api.getLeftTree)
}
// 用户列表
export const getUserListApi = async (param: UserListParam) => {
    return await http.get(Api.getUserList, param)
}
// 新增
export const addUserApi = async (param: AddUserModel) => {
    return await http.post(Api.addAndEditAndDel, param)
}
// 编辑
export const editUserApi = async (param: AddUserModel) => {
    return await http.put(Api.addAndEditAndDel, param)
}
// 删除
export const delUserApi = async (param: any) => {
    return await http.delete(Api.addAndEditAndDel, param)
}
// 获取分配角色弹框列表
// export const getRoleListApi = async (param: AssignRoleListParam) => {
//     return await http.get(Api.getRoleList, param)
// }
// 查询用户原来用有的角色id
export const getRoleIdApi = async (userId: number | string) => {
    return await http.getRestApi(Api.getRoleId, { userId: userId })
}
// 分配角色保存
export const assingRoleSaveApi = async (param: SelectRoleParam) => {
    return await http.post(Api.assignSave, param)
}
// 退出登录
export const loginOutApi = async (param: any) => {
    return await http.post(Api.loginOut, param)
}
// 修改密码
export const changePasswordApi = async (param: ChangePassword) => {
    return await http.post(Api.changePassword, param)
}
// 修改头像
export const changeAvatarApi = async (param: ChangeAvatar) => {
    return await http.post(Api.changeAvatar, param)
}
